﻿using FT.Architecture.Entities;
using FT.Architecture.Logging;
using FT.Architecture.NHibernate.SessionManagement;
using FT.Architecture.Queries;
using FT.Architecture.Repositories;

namespace FT.Architecture.NHibernate.Repositories
{
    public class NHibernateRepositoryService : IRepositoryService
    {
        private readonly ISessionProviderService sessionProviderService;
        private readonly IQueryExecutorService queryExecutorService;
        private readonly ILogService logService;

        public NHibernateRepositoryService(ISessionProviderService sessionProviderService, IQueryExecutorService queryExecutorService, ILogService logService)
        {
            this.sessionProviderService = sessionProviderService;
            this.queryExecutorService = queryExecutorService;
            this.logService = logService;
        }

        public virtual IRepository<T> GetRepository<T>() where T : class, IGenericEntity<long>
        {
            return new NHibernateRepository<T>(sessionProviderService, queryExecutorService, logService);
        }

        public virtual IGenericRepository<T, TId> GetRepository<T, TId>() where T : class, IGenericEntity<TId>
        {
            return new NHibernateGenericRepository<T, TId>(sessionProviderService, queryExecutorService, logService);
        }

        public virtual INonGenericRepository GetRepository()
        {
            return new NHibernateNonGenericRepository(sessionProviderService, logService);
        }
    }
}